//
//  ControllerTool.m
//  Zhihuijinfu
//
//  Created by 王笛 on 2016/11/29.
//  Copyright © 2016年 王笛. All rights reserved.
//

#import "ControllerTool.h"
#import "MMDrawerVisualState.h"
#import "LeftMenViewController.h"
#import "WDNavController.h"
#import "WDLoanManagerController.h"
#import "WDBusinessManagerController.h"
#import "WDFinancialProductController.h"
#import "WDCompanyAddressController.h"
#import "WDMyNotifyController.h"

@interface ControllerTool ()

@property (nonatomic,strong) MMDrawerController *drawerController;
@property (nonatomic,strong) LeftMenViewController *menuController;

@end

@implementation ControllerTool

WDSingletonM(OpenController);

+ (void)destroyInstance
{
    _instance = nil;
}

-(MMDrawerController *)getDrawerController
{
    if (!_drawerController) {
        
        _drawerController = [[MMDrawerController alloc] init];
        
         /*是否显示阴影效果*/
        _drawerController.showsShadow = NO;
        
         /*设置左侧抽屉菜单栏的宽度*/
        [_drawerController setMaximumLeftDrawerWidth:[UIScreen mainScreen].bounds.size.width * 0.7];
        
        //设置打开抽屉菜单的手势
        [_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
        
        //关闭抽屉菜单的手势
        [_drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
                
        [_drawerController setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
            
            MMDrawerControllerDrawerVisualStateBlock block = [MMDrawerVisualState slideVisualStateBlock];
            if (block) {
                block(drawerController,drawerSide,percentVisible);
            }
        }];
        
         /*设置左边控制器*/
        [_drawerController setLeftDrawerViewController:self.menuController];
        //设置中间控制器

    }
    
    if(self.isNotify) {//通知
        
        WDMyNotifyController *goodVC = [[WDMyNotifyController alloc] init];
        
        WDNavController *navVC = [[WDNavController alloc]initWithRootViewController:goodVC];
        
        [_drawerController setCenterViewController:navVC];
        
    } else {//登录的
        
        if ([WDVerify verifyStr:finance_getList inArr:[[NSUserDefaults standardUserDefaults] objectForKey:verStr]]) {//贷款管理
            
            WDLoanManagerController *goodVC = [[WDLoanManagerController alloc] init];
            
            WDNavController *navVC = [[WDNavController alloc]initWithRootViewController:goodVC];
            
            [_drawerController setCenterViewController:navVC];
            
        } else if ([WDVerify verifyStr:supplier_getList inArr:[[NSUserDefaults standardUserDefaults] objectForKey:verStr]]) {//商户维系
            
            WDBusinessManagerController *goodVC = [[WDBusinessManagerController alloc] init];
            
            WDNavController *navVC = [[WDNavController alloc]initWithRootViewController:goodVC];
            
            [_drawerController setCenterViewController:navVC];
            
        } else if ([WDVerify verifyStr:product_getList inArr:[[NSUserDefaults standardUserDefaults] objectForKey:verStr]]) {//金融产品
            
            WDFinancialProductController *goodVC = [[WDFinancialProductController alloc] init];
            
            WDNavController *navVC = [[WDNavController alloc]initWithRootViewController:goodVC];
            
            [_drawerController setCenterViewController:navVC];
            
        } else {//通讯录
            
            WDCompanyAddressController *goodVC = [[WDCompanyAddressController alloc] init];
            
            WDNavController *navVC = [[WDNavController alloc]initWithRootViewController:goodVC];
            
            [_drawerController setCenterViewController:navVC];
            
        }
    }
    
    
    return _drawerController;
}

- (LeftMenViewController *)menuController
{
    if (!_menuController) {
        _menuController = [[LeftMenViewController alloc] init];
    }
    return _menuController;
}

@end
